//
//  NQProvinceCell.m
//  ZLFastDoctor
//
//  Created by 李岚清 on 16/5/23.
//  Copyright © 2016年 LS. All rights reserved.
//

#import "NQProvinceCell.h"
#import "NQPrivence.h"

#define MAS_SHORTHAND
#define MAS_SHORTHAND_GLOBALS
#import <Masonry/Masonry.h>

@interface NQProvinceCell ()

@property (nonatomic, strong) UIButton *tipView;


@end

@implementation NQProvinceCell
#pragma mark - set/get
- (void)setPrivence:(NQPrivence *)privence{
    _privence = privence;
    //赋值数据
    self.textLabel.text = privence.name;
}

- (void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
    //改变tipView的选中状态
    self.tipView.selected = isSelected;
}

#pragma mark - 重写构造方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    if (self = [super initWithCoder:aDecoder]) {
        [self setupUI];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self.textLabel makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView);
        make.centerY.equalTo(self.contentView);
    }];
}


#pragma mark - 添加子控件及约束
- (void)setupUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    //添加到view自身上
    [self.contentView addSubview:self.tipView];
    //添加约束
    [self.tipView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView);
        make.centerY.equalTo(self.contentView);
        make.width.height.equalTo(30);
    }];
    [self.contentView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
}

#pragma mark - 懒加载子控件
- (UIButton *)tipView{
    if (!_tipView) {
        _tipView = [UIButton buttonWithType:UIButtonTypeCustom];
        //关闭与用户的交互
        _tipView.userInteractionEnabled = NO;
        [_tipView setBackgroundImage:[UIImage imageNamed:@"imageNoSelected"] forState:UIControlStateNormal];
        [_tipView setBackgroundImage:[UIImage imageNamed:@"imageSelected"] forState:UIControlStateSelected];
    }
    return _tipView;
}


@end
